home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / Gooey 1.2 / Gooey 68K ƒ / C Templates / mmModelessDialog.c < prev    next >
Encoding:
Text File  |  1994-04-14  |  22.1 KB  |  424 lines  |  [TEXT/KAHL]

  1. $$Loop ModelessDialogs
  2. $$Message MM Modeless Dialog, mm:mmMD_$Worksheet.name$.c
  3.  
  4. $$File mm:mmMD_$Worksheet.name$.c
  5. /*  mmMD_$Worksheet.name$                                 Handle this dialog */
  6. /*  $CopyRight$ */
  7.  
  8. /*    File name:  mmMD_$Worksheet.name$.c
  9.     Function:  Handle this modeless dialog.
  10.  
  11.     This dialog is called when:
  12.  
  13.     History: $Date$ Original by $Author$
  14.  
  15. */
  16.  
  17. /* ======================================================= */
  18. /* ======================================================= */
  19.  
  20. #include "mmCommon$Prototype.name$.h"    /* Common */
  21. #include "Common$Prototype.name$.h"        /* Common */
  22.  
  23. #include "$Worksheet.name$.h"
  24.  
  25. /* ======================================================= */
  26. /* ======================================================= */
  27.  
  28. /* Routine: Init_$Worksheet.name$ */
  29. /* Purpose: This procedures purpose is to set the window pointer to nil, */
  30. /* this is used to tell the other routines */
  31.  
  32. void Init_$Worksheet.name$(void)
  33. {
  34. Rect    tempRect;                                    /* Temporary rectangle */
  35. short    DType;                                    /* Type of dialog item */
  36. short    Index;                                    /* For looping */
  37. Handle    DItem;                                    /* Handle to the dialog item */
  38. ControlHandle    CItem, CTempItem;                    /* Control handle */
  39. Str255    sTemp;                                    /* Get text entered, temp holding */
  40. short    itemHit;                                    /* Get selection */
  41. short    temp;                                        /* Get selection, temp holding */
  42.  
  43.  
  44. Rec_$Worksheet.name$.theDialog = nil;                    /* Initialize to say that the dialog is not yet active */
  45.  
  46. $$Loop Control.type = Button
  47. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Button */
  48. $$EndLoop
  49. $$Loop Control.type = HotRect
  50. $$if Control.HotSpot
  51. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* HotSpot */
  52. $$endif
  53. $$EndLoop
  54. $$Loop Control.type = Checkbox
  55. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Checkbox */
  56. $$if Control.Selected
  57. Rec_$Worksheet.name$.Value_$Control.name$ = 1;
  58. $$endif
  59. $$if Control.Unselected
  60. Rec_$Worksheet.name$.Value_$Control.name$ = 0;
  61. $$endif
  62. $$EndLoop
  63. $$Loop Control.type = Radio
  64. Rec_$Worksheet.name$.Enable_$Control.name$ = $Cong))/* Only do if we are the window to update */
  65.     {
  66.     GetPort(&SavedPort);                            /* Get the current port */
  67.     SetPort(theWindow);                            /* Point to our port for drawing in our window */
  68.     if (Has.ColorQD)                                /* See if color QuickDraw is around */
  69.         {
  70.         GetForeColor(&Saved_ForeColor);            /* Save the fore color */
  71.         GetBackColor(&Saved_BackColor);            /* Save the back color */
  72.  
  73.         RGBForeColor(&Black_ForeColor);            /* Set the fore color to Black */
  74.         RGBBackColor(&White_BackColor);            /* Set the back color to White */
  75.         }                                        /* End of IF */
  76.  
  77. $$Loop Control.type = Button
  78. $$if Control.Default
  79.     /* This is the default selection, when RETURN is pressed. */
  80.     HiliteDefaultButton(theWindow,ResD_$Control.name$);
  81.  
  82. $$endif Control.Default
  83. $$EndLoop Control.type
  84. $$Loop Control.type = Line
  85.     /* Draw a line, $Control.FullName$ */
  86. $$if Control.GrayLine
  87.     PenPat(&qd.gray);                                        /* Set the gray pen pattern */
  88. $$endif Control.GrayLine
  89. $$if Control.LineWidth ! 1
  90.     PenSize($Control.LineWidth$,$Control.LineWidth$);
  91. $$endif Control.LineWidth
  92.     MoveTo($Control.LeftPosition$,$Control.TopPosition$);        /* Horz,vert, Move to starting position */
  93.     LineTo($Control.RightPosition$,$Control.BottomPosition$);    /* Horz,vert, Draw to the ending position */
  94. $$if Control.LineWidth ! 1
  95.     PenSize(1,1);
  96. $$endif Control.LineWidth
  97. $$if Control.GrayLine
  98.     PenPat(&qd.black);                                        /*  Back to default pen pattern  */
  99. $$endif Control.GrayLine
  100.  
  101. $$EndLoop
  102. $$Loop Control.type = StaticText
  103. $$if Control.SpecialText
  104.     /* Draw static text, $Control.FullName$ */
  105. $$if Control.TextColor ! Black
  106.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  107.         {
  108.         DrawingColor.red = 0x$Control.RedTextColor$;
  109.         DrawingColor.green = 0x$Control.GreenTextColor$;
  110.         DrawingColor.blue = 0x$Control.BlueTextColor$;
  111.         RGBForeColor(&DrawingColor);                    /* Set the fore color */
  112.         RGBBackColor(&Saved_BackColor);                    /* Set the back color */
  113.         }
  114. $$endif Control.TextColor
  115.     $$if Control.MultipleLine
  116.     SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
  117.     DrawStaticTextBox(sResD_$Control.name$,&tempRect,$Control.TextAlignment$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  118.     $$endif Control.MultipleLine
  119.     $$if Control.SingleLine
  120.     DrawStaticLine(sResD_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  121.     $$endif Control.SingleLine
  122. $$if Control.TextColor ! Black
  123.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  124.         {
  125.         RGBForeColor(&Black_ForeColor);                    /* Set the fore color */
  126.         RGBBackColor(&White_BackColor);                    /* Set the back color */
  127.         }
  128. $$endif Control.TextColor
  129.  
  130. $$endif Control.SpecialText
  131. $$EndLoop
  132. $$Loop Control.type = List
  133.     UpdateTheList(theWindow->visRgn,Rec_$Worksheet.name$.List_$Control.name$,&Rec_$Worksheet.name$.ListRect_$Control.name$,
  134.         $Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,true);
  135.  
  136. $$EndLoop
  137.     TextSize(12);
  138.     TextFont(systemFont);                                /* Select the Font that we want */
  139.     TextFace(0);                                        /* Select the style that we want */
  140.  
  141.     if (Has.ColorQD)                                /* See if color QuickDraw is around */
  142.         {
  143.         RGBForeColor(&Saved_ForeColor);            /* Restore the fore color */
  144.         RGBBackColor(&Saved_BackColor);            /* Restore the back color */
  145.         }                                        /* End of IF */
  146.  
  147.     U_Update_$Worksheet.name$(theWindow);            /* Call the user update routine */
  148.  
  149.     DrawDialog(theWindow);                            /* Draw the rest of the controls */
  150.     SetPort(SavedPort);                            /* Restore the port that we saved at the start */
  151.     }                                            /* End of IF */
  152. }
  153.  
  154. /* ======================================================= */
  155.  
  156. /* Routine: Open_$Worksheet.name$ */
  157. /* Purpose: This procedures purpose is to open this window and set all */
  158. /* of the initial conditions, such as default edit text. */
  159.  
  160. void Open_$Worksheet.name$(void)
  161. {
  162. TEHandle        ThisEditText; 
  163. Rect            tempRect;                            /* Temporary rectangle variable */
  164. short            DType;                                /* Type of dialog item */
  165. Handle            DItem;                                /* Handle to the dialog item */
  166. ControlHandle    CItem;                                /* Control handle */
  167. long            LTemp,LTemp2,theLong;                /* Get selection, temp holding */
  168.  
  169.  
  170. if (Rec_$Worksheet.name$.theDialog == NIL)
  171.     {
  172.     Rec_$Worksheet.name$.theDialog = GetNewDialog(ResD_$Worksheet.name$, NIL,  (WindowPtr)-1 );/* Bring in the dialog resource */
  173.     SetPort(Rec_$Worksheet.name$.theDialog);        /* Prepare to add conditional text */
  174.  
  175.     $$if Worksheet.Center
  176.     tempRect = Rec_$Worksheet.name$.theDialog->portRect;            /* Get the windows position and size */
  177.     $$if Worksheet.CenterHorz
  178.     tempRect.left = ((screenRect.bounds.right - screenRect.bounds.left) - (tempRect.right - tempRect.left)) / 2;    /* Center Horz */
  179.     $$endif Worksheet.CenterHorz
  180.     $$if Worksheet.CenterVert
  181.     tempRect.top = ((screenRect.bounds.bottom - screenRect.bounds.top) - (tempRect.bottom - tempRect.top)) / 3;    /* 1/3 vert */
  182.         if (tempRect.top < 40)                            /* Keep below the menu bar */
  183.         tempRect.top = 40;
  184.     $$endif Worksheet.CenterVert
  185.     MoveWindow(Rec_$Worksheet.name$.theDialog,tempRect.left,tempRect.top,true);
  186.     
  187.     $$endif
  188. $$if ModelessDialog.Movable
  189.     Doing_MovableModal = true;
  190.     
  191. $$endif ModelessDialog.Movable
  192. $$Loop Control.type = Button
  193.     /* Button */
  194.     SetupNormalControl(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,0);
  195.  
  196. $$EndLoop Control.type
  197. $$Loop Control.type = Checkbox
  198.     /* Checkbox */
  199.     SetupNormalControl(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  200.         Rec_$Worksheet.name$.Value_$Control.name$);
  201.  
  202. $$EndLoop Checkbox
  203. $$Loop Control.type = Radio
  204.     /* Radio button */
  205.     SetupNormalControl(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  206.         Rec_$Worksheet.name$.Value_$Control.name$);
  207.  
  208. $$EndLoop Radio
  209. $$Loop Control.type = List
  210.     /* Make a List */
  211.     Make_A_List(&Rec_$Worksheet.name$.List_$Control.name$,&Rec_$Worksheet.name$.ListRect_$Control.name$,
  212.         Rec_$Worksheet.name$.theDialog,sResD_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,true);
  213.  
  214. $$EndLoop
  215. $$Loop Control.type = HotRect
  216.     /* Draw a Hotspot or Rectangle */
  217.     SetupHotSpot(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,$Control.MakeHotSpot$,$Control.LineWidth$,
  218.         $Control.ShadowWidth$,sResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$);
  219.  
  220. $$EndLoop
  221. $$Loop Control.type = EditText
  222.     GetDItem(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,&DType,&DItem,&tempRect);/* Get the item handle */
  223.     GetIndString(sTemp,sResD_$Control.name$,1);            /* ...Edit text, default value */
  224.     SetIText(DItem,sTemp);                                /* Set the default text string */
  225.     SelIText(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,0,300);
  226.  
  227. $$EndLoop
  228. $$Loop Control.type = Popup
  229.     SetupPopupMenu(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  230.         mResD_$Control.name$,Rec_$Worksheet.name$.Value_$Control.name$);
  231.  
  232. $$EndLoop
  233. $$Loop Control.type = Picture
  234. $$if Control.NonGraphic
  235.     /* Draw a picture */
  236.     LTemp = ResD_N_$Control.name$;                        /* Picture ID and resize flag */
  237. $$if Control.ClipPicture
  238.     LTemp = 0x00010000 | LTemp;
  239. $$endif Control.ClipPicture
  240.     SetupTheItem(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,true,true,
  241.         Rec_$Worksheet.name$.Enable_$Control.name$,false,&tempRect,LTemp,0);
  242.  
  243. $$endif Control.NonGraphic
  244. $$EndLoop
  245. $$Loop Control.type = Palette
  246.     /* Draw a Palette */
  247.     SetupPalette(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  248.         $Control.NumRows$,$Control.NumColumns$,ResD_N_$Control.name$,$Control.HMethod$);
  249.  
  250. $$EndLoop
  251. $$Loop Control.type = Icon
  252. $$if Control.NonGraphic
  253.     /* Draw an Icon button */
  254.     SetupIconSicn(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  255.         ResD_N_$Control.name$,ResD_H_$Control.name$);
  256.  
  257. $$endif Control.NonGraphic
  258. $$EndLoop
  259. $$Loop Control.type = Sicn
  260.     /* Draw a Sicn */
  261. $$if Control.Graphic
  262.     SetupIconSicn(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  263.         ResD_N_$Control.name$,ResD_N_$Control.name$);
  264. $$endif Control.Graphic
  265. $$if Control.NonGraphic
  266.     SetupIconSicn(Rec_$Worksheet.name$.theDialog,ResDndLoop Control.type
  267.     }
  268. $$endif HasLists
  269.  
  270. if ((Rec_$Worksheet.name$.theDialog != nil)  && (Rec_$Worksheet.name$.theDialog  == theWindow))
  271.     {
  272.     CheckKeysInDialog(theWindow,&DoubleClick,theEvent,&itemHit);
  273.  
  274.     myPt = theEvent->where;                            /* Get the position where the mouse was pressed */
  275.     GlobalToLocal(&myPt);                            /* Change from global to local location */
  276.  
  277.     U_Hit_$Worksheet.name$(theWindow,&itemHit,&Rec_$Worksheet.name$.ExitDialog,theEvent);/* Give the user the itemhit */
  278.  
  279.     if (itemHit > 0)                                /* Skip if user set to zero */
  280.         {
  281.         GetDItem(theWindow, itemHit,&DType,&DItem,&tempRect);/* Get which item was pressed */
  282.         CItem = (ControlHandle)DItem;                /* Change the pointer for getting to the control */
  283.         }
  284.     
  285.     /* Handle it real time */
  286.     $$Loop Control.type = Button
  287.     if (itemHit == ResD_$Control.name$)                /* Handle the Button being pressed */
  288.         {
  289.         $$Link    Control.Select
  290.         $$if Control.ExitDialog
  291.         Rec_$Worksheet.name$.ExitDialog = true;        /* Close this dialog, exit */
  292.         $$endif Control.ExitDialog
  293.         }
  294.  
  295.     $$EndLoop Control.type
  296.     $$Loop Control.type = Checkbox
  297.     if (itemHit == ResD_$Control.name$)                /* Handle the checkbox being pressed */
  298.         {
  299.         temp = GetCtlValue(CItem);                    /* Get the current Checkbox value */
  300.         SetCtlValue(CItem, (temp + 1) & 1);            /* Toggle the value to the opposite */
  301.         Rec_$Worksheet.name$.Value_$Control.name$ = GetCtlValue(CItem);    /* Get the current Checkbox value */
  302.         $$if Control.HasLinks
  303.         if (Rec_$Worksheet.name$.Value_$Control.name$ == 0)
  304.             {
  305.             $$Link    Control.Deselect
  306.             }
  307.         else
  308.             {
  309.             $$Link    Control.Select
  310.             }
  311.         $$endif
  312.         }
  313.  
  314.     $$EndLoop Control.type
  315.     $$Loop Control.type = UButton
  316.     $$if Control.HasLinks
  317.     if (itemHit == ResD_$Control.name$)                /* Handle the Button being pressed */
  318.         {
  319.         $$Link    Control.Select
  320.         }
  321.  
  322.     $$endif
  323.     $$EndLoop Control.type
  324.     $$Loop Control.type = UToggle
  325.     if (itemHit == ResD_$Control.name$)                /* Handle the checkbox being pressed */
  326.         {
  327.         temp = GetCtlValue(CItem);                    /* Get the current Checkbox value */
  328.         SetCtlValue(CItem, (temp + 1) & 1);            /* Toggle the value to the opposite */
  329.         Rec_$Worksheet.name$.Value_$Control.name$ = GetCtlValue(CItem);    /* Get the current Checkbox value */
  330.         $$if Control.HasLinks
  331.         if (Rec_$Worksheet.name$.Value_$Control.name$ == 0)
  332.             {
  333.             $$Link    Control.Deselect
  334.             }
  335.         else
  336.             {
  337.             $$Link    Control.Select
  338.             }
  339.         $$endif
  340.         }
  341.  
  342.     $$EndLoop Control.type
  343.     $$Loop Control.type = Radio
  344.     if (itemHit == ResD_$Control.name$)            /* Handle the Radio being pressed */
  345.         {
  346.         SetCtlValue(CItem,1);
  347.         Rec_$Worksheet.name$.Value_$Control.name$ = 1;    /* Set the current Radio value */
  348.  
  349.         $$Loop RadioGroup
  350.         ClearTheRadio(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,&Rec_$Worksheet.name$.Value_$Control.name$);
  351.         $$EndLoop RadioGroup
  352.         $$Link    Control.Select
  353.         }
  354.  
  355.     $$EndLoop Control.type
  356.     $$Loop Control.type = HotRect
  357.     $$if Control.HotSpot
  358.     $$if Control.HasLinks
  359.     if (itemHit == ResD_$Control.name$)                /* Handle the HotSpot being pressed */
  360.         {
  361.         $$Link    Control.Select
  362.         }
  363.  
  364.     $$endif
  365.     $$endif Control.HotSpot
  366.     $$EndLoop
  367.     $$Loop Control.type = Popup
  368.     /* Popup */
  369.  
  370.     $$EndLoop
  371.     $$Loop Control.type = Picture
  372.     $$if Control.NonGraphic
  373.     $$if Control.HasLinks
  374.     if (itemHit == ResD_$Control.name$)                /* Handle the Picture being pressed */
  375.         {
  376.         $$Link    Control.Select
  377.         }
  378.  
  379.     $$endif
  380.     $$endif Control.NonGraphic
  381.     $$EndLoop
  382.     $$Loop Control.type = Palette
  383.     /* Palette */
  384.  
  385.     $$EndLoop
  386.     $$Loop Control.type = Icon
  387.     $$if Control.NonGraphic
  388.     $$if Control.HasLinks
  389.     if (itemHit == ResD_$Control.name$)                /* Handle the Icon being pressed */
  390.         {
  391.         $$Link    Control.Select
  392.         }
  393.  
  394.     $$endif
  395.     $$endif Control.NonGraphic
  396.     $$EndLoop
  397.     $$Loop Control.type = Sicn
  398.     $$if Control.NonGraphic
  399.     $$if Control.HasLinks
  400.     if (itemHit == ResD_$Control.name$)                /* Handle the Sicn being pressed */
  401.         {
  402.         $$Link    Control.Select
  403.         }
  404.  
  405.     $$endif
  406.     $$endif Control.NonGraphic
  407.     $$EndLoop
  408.  
  409.     }
  410.  
  411. if (Rec_$Worksheet.name$.ExitDialog)                /* Do the close of the dialog */
  412.     {
  413.     Close_$Worksheet.name$(Rec_$Worksheet.name$.theDialog);
  414.     Rec_$Worksheet.name$.theDialog = nil;                    /* Clear it for future checks */
  415.     }
  416. }
  417.  
  418. /* ======================================================= */
  419. /* ======================================================= */
  420. $$CloseFile
  421. $$EndLoop
  422.  
  423.  
  424.